// index.js
const fs = require('fs').promises;
const path = require('path');
const MapTileManager = require('./MapTileManager');
const GoogleTileSystem = require('./GoogleTileSystem');
const sharp = require('sharp');

async function main() {
    // 定义输入截图目录和输出切片目录
    const tileDir = '/Users/laotie/Library/Application Support/labelmap/tiles/zoom19';

    // 初始化切片系统
    const tileSystem = new GoogleTileSystem();

    // 创建 MapTileManager 实例
    const processor = new MapTileManager(tileSystem);
    try {
        const dirs = await fs.readdir(tileDir);
        for (const dir of dirs) {
            const dirpath = path.join(tileDir, dir);
            const stat = await fs.stat(dirpath);
            if (stat.isDirectory()) {
                const files = await fs.readdir(dirpath);
                for (const file of files) {
                    if (file.endsWith('.png')) {
                        const imagePath = path.join(dirpath, file);
                        const imageBuffer = await fs.readFile(imagePath);
                        let result = await processor.isImageComplete(imageBuffer, 512);
                        console.log(`analyze ${dir}-${file}, result = ${result}`);
                    }
                }
            }

        }
    } catch (error) {
        console.error(`Error reading directory ${dir}:`, error);
    }
}

main().catch((err) => {
    console.error('处理过程中发生错误:', err);
});
